#include <cstdio>
#include <iostream>
using namespace std;
#define N 100
int A[N][N], B[N][N];
int main()
{
	int n, m, i, j;
	cin >> m >> n;
	int y = 0, total = n * m;
	for (i = 0; i < m; i++)
	{
		for (j = 0; j < m; j++)
		{
			cin >> A[i][j];
		}
	}
	for (i = 0; i < m; i++)
	{
		for (j = 0; j < m; j++)
		{
			cin >> B[i][j];
		}
	}
	for (i = 0; i < m; i++)
	{
		for (j = 0; j < m; j++)
		{
			if (A[i][j] == B[i][j])
			{
				y++;
			}
		}
	}
	double ans = ((double)y / (double)total) * 100;
	printf("%.2lf\n", ans);
	return 0;
}